; 这里做了改动，原来是在这里定义的disp_pos
; 现在被移动到了global.c中了。
extern disp_pos

[SECTION .text]
global disp_str
global disp_color_str
global out_byte
global in_byte

; 显示一个字符串，相当于void disp_str(char *str)
disp_str:
	push ebp
	mov ebp, esp
	
	; str字符串首地址
	mov esi, dword [ebp + 8]
	mov edi, dword [disp_pos]
	
	mov ah, 0Fh
.1:
	lodsb ; 相当于mov al, byte [ds:esi]  inc esi
	cmp al, 0
	jz .2
	
	cmp al, 0Ah
	jnz .3
	
	push eax
	mov eax, edi
	mov bl, 160
	div bl
	and eax, 0FFh
	inc eax
	mov bl, 160
	mul bl
	mov edi, eax
	pop eax
	jmp .1
.3:
	mov [gs:edi], ax
	add edi, 2
	jmp .1
	
.2:
	mov dword [disp_pos], edi
	
	pop ebp
	ret
	
disp_color_str:
	push ebp
	mov ebp, esp
	
	mov esi, [ebp + 8]
	mov edi, dword [disp_pos]
	mov ah, byte [ebp + 12]
	
.1:
	lodsb
	test al, al
	jz .2
	
	cmp al, 0Ah
	jnz .3
	
	push eax
	mov eax, edi
	mov bl, 160
	div bl
	and eax, 0FFh
	inc eax
	mov bl, 160
	mul bl
	mov edi, eax
	pop eax
	jmp .1
.3:
	mov [gs:edi], ax
	add edi, 2
	jmp .1
	
.2:
	mov dword [disp_pos], edi
	
	mov esp, ebp
	pop ebp
	ret
	
; void out_byte(u16 port, u8 value);
out_byte:
	mov edx, [esp + 4]
	mov al, [esp + 4 + 4]
	out dx, al
	nop
	nop
	ret
	
; u8 in_byte(u16 port);
in_byte:
	mov edx, [esp + 4]
	xor eax, eax
	in al, dx
	nop
	nop
	ret